<template>
  <ul class="list-container">
    <li v-for="(item, i) in list" :key="i">
      <span @click="handleClick(item)" :class="{ active: item.isSelect }">
        {{ item.name }}
      </span>
      <span
        v-if="item.aside"
        @click="handleClick(item)"
        class="aside"
        :class="{ active: item.isSelect }"
      >
        {{ item.aside }}
      </span>
      <!-- 显示当前组件 -->
      <List :list="item.children" @select="handleClick" />
    </li>
  </ul>
</template>

<script>
export default {
  name: "List",
  props: {
    // [{ name:content , isSelect: true, children:[ { name:content , isChosen: true, children:[...] }] } ]
    list: {
      type: Array,
      default: () => [],
    },
  },
  methods: {
    handleClick(item) {
      if (!item.isSelect) {
        this.$emit("select", item);
      }
    },
  },
};
</script>

<style lang="less" scoped>
@import "~@/styles/var.less";
.list-container {
  list-style: none;
  padding: 0;
  .list-container {
    margin-left: 1em;
  }
  li {
    min-height: 40px;
    line-height: 40px;
    font-size: 14px;
    cursor: pointer;
    &:hover {
      background-color: rgba(235, 235, 235, 0.5);
    }
    .active {
      color: @warn;
      font-size: 1.2em;
    }
  }
}
.aside {
  font-size: 12px;
  margin-left: 1em;
  color: @gray;
}
</style>